package com.hkyp.ss.course.provider.repository;

import com.hkyp.ss.course.provider.model.NavigationItem;
import com.hkyp.ss.course.provider.repository.baseRepository.BaseRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface NaviItemRepository extends BaseRepository<NavigationItem,Long> {

    /**
     * 查询最大的code
     * 测试可用
     */
    @Query(value = "select max(a.code) from navigation_item a", nativeQuery = true)
    Integer getMaxCode();

    /**
     * 查找指定父级中最大子级
     * 测试可用
     */
    @Query(value = "select max(a.code) from navigation_item a where a.code > (:lesser) and a.code < (:greater);", nativeQuery = true)
    Integer getMaxCodeFromParent(@Param("lesser") Long lesser, @Param("greater") Long greater);



    /**
     * 查询指定范围内，是否存在重复导航栏名称
     *
     * 测试可用
     */
    //发送sql:
    //select navigation0_.id as col_0_0_ from navigation_item navigation0_ where navigation0_.value=? and navigation0_.code>? and navigation0_.code<? limit ?
    boolean existsByValueAndCodeGreaterThanAndCodeLessThan(String value, Long lesser, Long greater);

    // 查询一级导航栏用
    boolean existsByValueAndGrade(String value, Integer grade);

    List<NavigationItem> findAllByCodeIn(Iterable<Long> codes);

}